package com.inwk.valoepi.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;

import com.inwk.valoepi.managers.PageManager;

public class MainPage extends Page {
	
	private String mainPageXPathLocator = "//div[@id='wrap']//div[@class='item-wrapper clearfix']";

	@FindBy(xpath = "//div[@class='header-nav']//img[@alt='logo']")
	private WebElement selfLink;
	
	@FindBy(xpath = "//div[@class='header-nav']//div[@class='icon icn-profile']")
	private WebElement userMenu;
	
	@FindBy(xpath = "//div[@class='item-wrapper clearfix']//a[contains(@href,'Product-list')]")
	private WebElement buyLink;
	
	public MainPage(PageManager pm) {
		super(pm);
	}

	public void doLogout() {
		new Actions(webDriver)
		.moveToElement(userMenu)
		.perform();
		wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='header-nav-item']//a[@id='portalUserLogoutLink']"))).click();
	}
	
	public ShopPage goToShopPage() {
		buyLink.click();
		return pm.shopPage;
	}

	@Override
	public boolean isCurrentPage() {
		return isElementPresent(mainPageXPathLocator);
	}
}
